<?php


namespace app\erp\controller;


use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;
use Darabonba\OpenApi\Models\Config;
use think\Controller;

class SendPhoneMsg extends Controller
{
    public function _initialize()
    {

    }
    // 发送短信
    /*
     * 新订单通知：SMS_225925355 {新订单提醒}-您好，军网平台有新的订单，单号：${order}，金额：${money}。地址：${address}。请及时处理。
     * 到账通知：SMS_225910508 {客户款到账提醒}-尊敬的合作伙伴您好，军网平台订单，单号：${order}，金额：${money}。客户款已到账，请及时查看，如有疑问可点击系统质疑按钮。
     * 付款通知：SMS_225935234 {货款支付提醒}-尊敬的合作伙伴您好，军网平台订单，单号：${order}，金额：${money}。货款已支付，请及时查看，如有疑问可点击系统质疑按钮。
     */
    public function sendMsg($phone, $tpl_code, $param)
    {
        $post_json = json_encode($param);
        $client = self::createClient();
        $sendSmsRequest = new SendSmsRequest ([
            "signName" => "泰龙吉",
            "phoneNumbers" => $phone,
            "templateCode" => $tpl_code,
            "templateParam" => $post_json
        ]);
        $result = $client->sendSms($sendSmsRequest);
        return $result;
    }

    public static function createClient()
    {
        $accessKeyId = 'LTAIeRWUxR6rp7sj';
        $accessKeySecret = 'n4qEWLCengJ012UAWl7UJvMOVMLgXY';
        $config = new Config ([
            "accessKeyId" => $accessKeyId,
            "accessKeySecret" => $accessKeySecret
        ]);
        // 访问的域名
        $config->endpoint = "dysmsapi.aliyuncs.com";
        return new Dysmsapi ($config);
    }
}